package cn.tedu.basic.Test1;


//测试模拟多线程编程
public class Test5_Thread {
    public static void main(String[] args) {
        //使用线程类
        MyRunnable mth =new MyRunnable();
        Thread th =new Thread();
        th.start();
        th.setName("you");
        mth.start();
        mth.setName("zhang");
        HerRunnable hrn=new HerRunnable();
        Thread th1 =new Thread(hrn);
        th1.start();
        th1.stop();
        KongJie target =new KongJie();
        Thread thr = new Thread(target);
        thr.start();
        thr.setName("张如媛");
        thr.stop();

    }
}
//定义线程类，实现Runnable接口
class MyRunnable extends Thread implements Runnable {
    //把业务放在重写run（）方法里
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            //获取线程名称
            System.out.println(Thread.currentThread().getName() + "===" + i);
            System.out.println(Thread.currentThread().getId() + "===" + i);
        }
    }
}
class HerRunnable implements Runnable {
        @Override
        public void run() {
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName() + "===" + i);
                System.out.println(Thread.currentThread().getName() + "===" + i);
            }
        }
    }

class KongJie implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i <10 ; i++) {
            System.out.println(Thread.currentThread().getName()+"=="+i);
            System.out.println(Thread.currentThread().getId()+"=="+i);
        }
    }
}
class Doctor implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i <11 ; i++) {
            System.out.println(Thread.currentThread().getName()+"=="+i);
            System.out.println(Thread.currentThread().getId()+"=="+i);

        }
    }
}

